import { pipeline } from '@huggingface/transformers'
import { createClient } from '@/lib/supabase/server';
const generateEmbedding = await pipeline('feature-extraction','Xenova/all-MiniLM-L6-v2')

const title = 'First post!'
const body = 'Hello world!'

// Generate a vector using Transformers.js
const output = await generateEmbedding(body, {
  pooling: 'mean',
  normalize: true,
})

// Extract the embedding output
const embedding = Array.from(output.data)
const supabase = await createClient();
// Store the vector in Postgres
const { data, error } = await supabase.from('documents').insert({
  title,
  body,
  embedding,
})